-
Couldn't load subscription status.
- Fork 14
CLOUDP-304929: xgen-IPA-102-collection-identifier-camelCase #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d82590d to
a8e254c
Compare
b4350a1 to
e5e3d89
Compare
|
Will apply approach for each path based on @lovisaberggren comment and also style from refactor PR. Back to draft |
| * @param {string} str - The string to check | ||
| * @returns {boolean} - True if the string is in camelCase, false otherwise | ||
| */ | ||
| export function isCamelCase(str) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI there is a spectral function we can use to check camel case
import { casing } from '@stoplight/spectral-functions'; like here https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/rulesets/functions/eachCustomMethodMustUseCamelCase.js#L3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have considered it but preference is to have casing defined. Will change it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the spectral function, see
openapi/tools/spectral/.spectral.yaml
Lines 27 to 29 in 698e772
| function: pattern # casing? | |
| functionOptions: | |
| match: "/^[a-z$_]{1}[A-Z09$_]*/" # type: camel ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also
openapi/tools/spectral/.spectral.yaml
Lines 37 to 39 in 698e772
| function: pattern # casing? | |
| functionOptions: | |
| match: "^[A-Z].*" # type: pascal ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still use this helper function? We can remove it if we are going with Spectral function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing helper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| function checkViolations(pathKey, path) { | ||
| const violations = []; | ||
| const pathSegments = pathKey.split('/').filter((segment) => segment.length > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to slice the prefix before looking at collectionIdentifiers
(Similar to here
openapi/tools/spectral/ipa/rulesets/functions/eachPathAlternatesBetweenResourceNameAndPathParam.js
Line 34 in e237b66
| const prefix = getPrefix(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go with ignoring some specific use cases rather than having prefix.
In this case we need v2 to be ignored.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Used spectral native way to configure values.
Will fix eachPathAlternatesBetweenResourceNameAndPathParam.js file once we review this PR and approve it.
Will update our spec to avoid hardcoded values that depend on downstream schema.
| if (!segment) return; | ||
|
|
||
| // Skip path parameter validation if it matches the expected format | ||
| if (isPathParam(segment)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we are not skipping pathParams, instead we are still validating them. This rule should look for collectionIdentifiers only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not skipping
We do not have rule to cover validation for path param
collectionIdentifiers only
Currently we do have those as part of the collection identifiers. e.g
paths./api/atlas/v2/groups/{groupId}/clusters/{clusterName}/globalWrites/managedNamespaces.delete
I did checked briefly and could not find an rule to validate camel case for path params.
No strong opinion on my side. I have documented this rule to cover path params as well but can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning towards checking for more use cases (and documenting those).
Leaving with no action however happy to change it if we do have specific validation for this already or based on your feedback and opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is no guideline about path param (i.e. resourceID) format in IPA-102. Maybe we can consider validating it after defining a guideline about resourceID format and then validating with a rule that just looks for that guideline. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline. We need to update rule description and name to reflect that it validates whole path correctness.
Then we can do all validation here. Thank you @yelizhenden-mdb
| } | ||
|
|
||
| // Skip empty identifiers | ||
| if (identifier.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not think of any empty identifier case? Do we expect such cases like /api/atlas/v2/resource/:customMethod
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect such cases like /api/atlas/v2/resource/:customMethod
My approach is to cover all possible cases and have clear handling for those.
Since you made comment I think we can have it as error use case?
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can have it as test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Adding extra details and tests.
|
Noticed I missed test for //. Will add it in follow up PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, some nits and one Q
| paths: { | ||
| '/resource_groups': {}, | ||
| }, | ||
| }, | ||
| errors: [ | ||
| { | ||
| code: 'xgen-IPA-102-collection-identifier-camelCase', | ||
| message: | ||
| "Collection identifiers must be in camelCase. Path segment 'resource_groups' in path '/resource_groups' is not in camelCase. http://go/ipa/102", | ||
| path: ['paths', '/resource_groups'], | ||
| severity: DiagnosticSeverity.Warning, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: If the path is for example /resource_groups/{id}/resource_keys, will there be two errors, one for resource_groups and one for resource_keys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single violation with 2 errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, could you add a test case for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extended multiple test cases.
Co-authored-by: Lovisa Berggren <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TY!
Collection Identifier camelCase Rule (xgen-IPA-102-collection-identifier-camelCase):
Enforces camelCase naming convention for resource identifiers
Prevents use of kebab-case, snake_case, or PascalCase
Also validates custom method names in the path